home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93c.txt / 000024_icon-group-sender _Wed Jul 21 08:48:31 1993.msg < prev    next >
Internet Message Format  |  1994-02-02  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Wed, 21 Jul 1993 10:50:24 MST
  2. Message-Id: <9307211546.AA32785@enlil.premenos.sf.ca.us>
  3. From: Ken Walker <kwalker@shara.premenos.sf.ca.us>
  4. Subject: Re: Mysteries of "every"
  5. To: icon-group@cs.arizona.edu
  6. Date: Wed, 21 Jul 93 8:48:31 PDT
  7. In-Reply-To: <706461@MTS.cc.Wayne.edu>; from "Paul_Abrahams@MTS.cc.Wayne.edu" at Jul 20, 93 9:35 pm
  8. Mailer: Elm [revision: 66.25]
  9. Status: R
  10. Errors-To: icon-group-errors@cs.arizona.edu
  11.  
  12. > Paul Abrahams (abrahams@acm.org) writes:
  13. > Yet I've looked again at pages 15-16 of the Icon book and I still don't
  14. > get it.  The explanation of resumption on p. 15 is in terms of failure,
  15. > and there's no failure in the expression of my example.  The description
  16. > of "every" on p. 16 says that "expr1 is first evaluated and then
  17. > repeatedly resumed to produce all its values."  I would have thought that
  18. > resuming an expression that doesn't fail would cause it to be
  19. > =completely= reevaluated.
  20.  
  21. The expression
  22.  
  23.     every <expr>
  24.  
  25. acts the same as
  26.  
  27.     <expr> & &fail
  28.  
  29. (unless <expr> contains break or continue). failure and resumption are
  30. two halves of the same thing. When something fails it initiates backtracking
  31. and backtracking ends with something being resumed (or by leaving a bounded
  32. expression). While "every" may not be described in terms of failure, it
  33. does initiate backtracking exactly the way failure does.
  34.  
  35. To understand what gets recomputed and what does not you need to think
  36. in terms of executation order. It may help to convert an expression into
  37. a postfix notation. Your expression
  38.  
  39. every retval :=  8 * retval + ord(!s) - ord("0")
  40.  
  41. might be converted into someting like the following. "Normal" execution is
  42. left to right and backtracking is right to left. Backtracking ends as soon
  43. as it finds something to resume. When the resumed operation produces another
  44. value execution continues forward again.
  45.  
  46. (retval ((((8 retval *) (ord (s !) invoke1)) +) (ord "0" invoke1) -) :=) every
  47. ******************************* ^                                          |
  48.                *                |                                          |
  49.                *                --------------------------------------------
  50.          not recomputed                backtracking loop, recomputed
  51.  
  52. Does this help?
  53.  
  54.    Ken Walker, kwalker@premenos.sf.ca.us
  55.